package servlet.manage.nav;

import model.NavModel;
import net.sf.json.JSONArray;
import service.INavService;
import service.impl.NavServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/NavSelect")
public class NavSelectServlet  extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        req.setCharacterEncoding("UTF-8");//请求编码格式为utf-8
//        resp.setCharacterEncoding("UTF-8");//响应编码格式为utf-8
//        resp.setContentType("text/json;charset=utf-8");//解决传值乱码

        INavService iNavService =new NavServiceImpl();
        List<NavModel> list =iNavService.getNavModelList();

//        req.setAttribute("list",list);
//        req.getRequestDispatcher("/back/NavSelect.jsp").forward(req,resp);
        //需要将list 转化成json对象需要引用包
        JSONArray jsonArray= JSONArray.fromObject(list);//栈溢出
        resp.getWriter().println(jsonArray.toString());

    }
}
